import Vue from 'vue';
// import Vuex from 'vuex';
import createVuexAlong from 'vuex-along'

Vue.use(Vuex);

const store = new Vuex.Store({
        state: {  //要设置的全局访问的state对象
            //设置初始值
            blogCount: 0, //文章总数
            viewCount: 0, //访问量
            commentCount: 0,//评论数
            messageCount:0, //留言数
            typeVal:1, //分类额专栏页码
            homeVal:1, //首页的页码
            tagVal:1, //标签的页码
            source: 'blog', //blog所属类别
            typeId: '', //分类id
            tagId:'', //标签id
            // homeBlog: [], //保存首页博客信息
        },
        getters:{ //实时监听state值的变化（最新变化）
            getblogCount: state => {
                return state.blogCount
            },
            getviewCount: state => {
                return state.viewCount
            },
            getcommentCount: state => {
                return state.commentCount
            },
            getmessageCount: state => {
                return state.messageCount
            },
            getTypeVal: state => {
                return state.typeVal
            },
            getHomeVal: state => {
                return state.homeVal
            },
            getTagVal: state => {
                return state.tagVal
            },
            getSource: state => {
                return state.source
            },
            getTypeId: state => {
                return state.typeId
            },
            getTagId: state => {
                return state.tagId
            },
            // getHomeBlog: state => {
            //     return state.homeBlog
            // }
        },
        mutations:{ //唯一允许更改state
            changeblogCount(state,n){
                state.blogCount = n
            },
            changeviewCount(state,n){
                state.viewCount = n
            },
            changecommentCount(state,n){
                state.commentCount = n
            },
            changemessageCount(state,n){
                state.messageCount = n
            },
            changeTypeVal(state,n){
                state.typeVal = n
            },
            changeHomeVal(state,n){
                state.homeVal = n
            },
            changeTagVal(state,n){
                state.tagVal = n
            },
            changeSource(state,n){
                state.source = n
            },
            changeTypeId(state,n){
                state.typeId = n
            },
            changeTagId(state,n){
                state.tagId = n
            },
            // changeHomeBlog(state,n){
            //     state.homeBlog = n
            // },
        },
        actions:{ //触发更改
            changeblogCountFun(context,n){
                context.commit("changeblogCount",n)
            },
            changeviewCountFun(context,n){
                context.commit("changeviewCount",n)
            },
            changecommentCountFun(context,n){
                context.commit("changecommentCount",n)
            },
            changemessageCountFun(context,n){
                context.commit("changemessageCount",n)
            },
            changeTypeValFun(context,n){
                context.commit("changeTypeVal",n)
            },
            changeHomeValFun(context,n){
                context.commit("changeHomeVal",n)
            },
            changeTagValFun(context,n){
                context.commit("changeTagVal",n)
            },
            changeSourceFun(context,n){
                context.commit("changeSource",n)
            },
            changeTypeIdFun(context,n){
                context.commit("changeTypeId",n)
            },
            changeTagIdFun(context,n){
                context.commit("changeTagId",n)
            },
            // changeHomeBlogFun(context,n){
            //     context.commit("changeHomeBlog",n)
            // },
        },
        plugins: [
            createVuexAlong()
        ]
    }
);

export default store;